<template>
  <div class="input-number">
    <button @click="handleSub">
      -
    </button>
    <input type="text" v-model="value" />
    <button @click="handleAdd">
      +
    </button>
  </div>
</template>

<script>
export default {
  // props: {
  //   count: {
  //     type: Number,
  //     required: true
  //   }
  // },
  // // 声明当前组件中触发的自定义事件
  // emits: ['update'],
  props: ['modelValue'],
  emits: ['update:modelValue'],
  computed: {
    value: {
      get() {
        return this.modelValue
      },
      set (value) { 
        this.$emit('update:modelValue', value)
      }
    }
  },
  methods: {
    handleSub () {
      // 减
      if (this.value > 1) {
        this.value--
      }
    },
    handleAdd () {
      this.value++
    }
  }
}
</script>

<style scoped>
.input-number button {
  cursor: pointer;
  border-width: 1px;
  background: #f1f1f1;
  width: 17px;
  height: 20px;
  line-height: 16px;
  vertical-align: middle;
  position: static;
  float: left;
  outline: 0;
  text-align: center;
  box-sizing: border-box;
  border: 1px solid #cbcbcb;
  padding: 0;
}

.input-number button.disabled {
  color: #ccc;
  cursor: not-allowed;
}

.input-number input {
  font-size: 12px;
  border-width: 1px 0;
  width: 46px;
  position: static;
  float: left;
  outline: 0;
  text-align: center;
  box-sizing: border-box;
  height: 20px;
  color: #232326;
  border: 1px solid #cbcbcb;
  background: #fff;
  line-height: 18px;
  vertical-align: middle;
  padding: 0;
}

.input-number input:focus {
  outline: none;
}
</style>